<template>
  <el-form-item label="图片类型">
    <el-select v-model="value" @change="sendCode" placeholder="请选择" clearable>
      <el-option
        v-for="item in options"
        :key="item.functionId"
        :label="item.functionName"
        :value="item.functionCode"
      ></el-option>
    </el-select>
  </el-form-item>
</template>

<script>
import { requestAPI } from "@/api/commonRequest";
import { crmApis } from "@/api/apiList/crm";
export default {
  name: "imageType",
  props: {
    imageType: {
      value: String
    }
  },
  data() {
    return {
      options: this.getData(),
      value: this.imageType.value
    };
  },
  mounted: function() {
    this.getData();
  },
  methods: {
    getData: function() {
      let that = this;
      let queryObj = {
        // api配置
        apiConfig: crmApis.crmDbFuncTypeQueryFindAll,
        // 需要调用的API服务配置
        apiServices: [
          {
            //表格中台返回网格的字段
            apiQueryRow: ["functionId","functionCode", "functionName"]
          }
        ],
        //条件/实体参数（变量），根据typeParam中的定义配置
        variables: {
          pageSize: 1000,
          pageIndex: 1,
          //当前中台使用的名称有dataInfo、info，具体查看API文档
          dataInfo: {
            groupCode:'1',
            oemCode:"1"
          } //值列表编码
        }
      };
      let paramD = that.$getParams(queryObj);
      // 调用中台API方法（可复用）
      requestAPI(paramD).then(response => {
        if (
          response.result == "1" &&
          response.rows != ""
        ) {
          that.options = response.rows;
        }
      });
    },
    sendCode() {
      this.$emit("changeCode", this.value);
      for(let i=0;i<this.options.length;i++){
        if(this.options[i].functionCode===this.value){
          this.$emit('getId',this.options[i].functionId)
        }
      }
    },
    reset: function() {
      let that = this;
      this.value = "";
      if(this.value==="43FE222040E59162E0530100007FDAAB"){
        this.value=""
      }
    }
  }
};
</script>
<style scoped>
</style>
